package br.com.center.loja.ws.dto.converter;

import java.util.ArrayList;
import java.util.List;

import br.com.center.loja.model.OrderItem;
import br.com.center.loja.ws.dto.OrderItemDTO;

public class OrderItemDTOConverter implements Converter<OrderItem, OrderItemDTO > {

	private ProductDTOConverter productConverter = new ProductDTOConverter();
	
	@Override
	public OrderItemDTO to(OrderItem element) {
		OrderItemDTO dto = new OrderItemDTO();
		dto.setCode(element.getCode());
		dto.setDiscount(element.getDiscount());
		dto.setPrice(element.getPrice());
		dto.setProduct(productConverter.to(element.getProduct()));
		dto.setQuantity(element.getQuantity());		
		return dto;
	}

	@Override
	public OrderItem from(OrderItemDTO element) {
		OrderItem item = new OrderItem();
		item.setCode(element.getCode());
		item.setDiscount(element.getDiscount());
		item.setPrice(element.getPrice());
		item.setProduct(productConverter.from(element.getProduct()));
		item.setQuantity(element.getQuantity());		
		return item;
	}

	@Override
	public List<OrderItemDTO> to(List<OrderItem> elements) {
		
		List<OrderItemDTO> result = new ArrayList<OrderItemDTO>();
		
		for (OrderItem element : elements) {
			result.add(to(element));
		}
		
		return result;		
	}

	@Override
	public List<OrderItem> from(List<OrderItemDTO> elements) {
		List<OrderItem> result = new ArrayList<OrderItem>();
		
		for (OrderItemDTO element : elements) {
			result.add(from(element));
		}
		
		return result;
	}

}
